#include <dbg.h>
#include <gtest/gtest.h>

#include <climits>

using namespace std;

class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int res = 0;
        int minPrice = INT_MAX;
        for (int p : prices) {
            minPrice = min(minPrice, p);
            res = max(res, p - minPrice);
        }
        return res;
    }
};

TEST(maxProfit_Test1, maxProfit) {
    Solution s;

    vector<int> prices{7, 1, 5, 3, 6, 4};
    EXPECT_EQ(s.maxProfit(prices), 5);
}

TEST(maxProfit_Test2, maxProfit) {
    Solution s;

    vector<int> prices{7, 6, 4, 3, 1};
    EXPECT_EQ(s.maxProfit(prices), 0);
}

int main(int argc, char** argv) {
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}